package com.gjm.tool.modifyLog.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gjm.tool.modifyLog.domain.ModifyHistoryLog;
import com.gjm.tool.modifyLog.mapper.ModifyHistoryLogMapper;
import com.gjm.tool.modifyLog.service.IModifyHistoryLogService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 修改历史记录Service业务层处理
 *
 * @author admin
 */
@Service
public class ModifyHistoryLogServiceImpl extends ServiceImpl<ModifyHistoryLogMapper, ModifyHistoryLog> implements IModifyHistoryLogService {
    @Resource
    private ModifyHistoryLogMapper modifyHistoryLogMapper;

    /**
     * 获取历史值
     *
     * @param tableName           表名
     * @param tablePrimaryIdName  表主键id名称
     * @param tablePrimaryIdValue 表主键值
     * @return 获取历史值
     */
    @Override
    public Map<String, Object> getOldData(String tableName, String tablePrimaryIdName, String tablePrimaryIdValue) {
        if (StrUtil.isBlank(tableName) || StrUtil.isBlank(tablePrimaryIdName) || StrUtil.isBlank(tablePrimaryIdValue)) {
            return null;
        }
        return baseMapper.getOldData(tableName, tablePrimaryIdName, "'" + tablePrimaryIdValue + "'");
    }

    @Override
    public List<String> getFields(String tableName) {
        return baseMapper.getFields(tableName);
    }
}
